<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
// let students = ['张三', '李四', '王五', '赵六', '孙七'];

// function names() {
//   const index = Math.floor(Math.random() * students.length);

//   return students[index];
// }
// console.log(names()); 


let arr =['龙禹同','李金歌','于楠','赵一琦','卢婧妍','苑光硕','孙凤睿','刚志远']
let newarr=[]
function rollcall(){
    //随机生成下标 0-7
let index= Math.floor(Math.random()*(arr.length-1-0+1)+0)
// 取到的第一个名字
    let index1name = arr[index]
// 截取已经找到的元素
    newarr=arr.splice(index,1)
// 获取第二个下标
    let index2 = Math.floor(Math.random()*(arr.length-1-0+1)+0)
    newarr.push(arr.splice(index2,1)[0])
    let index3 = Math.floor(Math.random()*(arr.length-1-0+1)+0)
    newarr.push(arr.splice(index3,1)[0])
    let index4 = Math.floor(Math.random()*(arr.length-1-0+1)+0)
    newarr.push(arr.splice(index4,1)[0])
    // console.log('--',index,index2)
// 查看结果
    // console.log(index1name,arr[index2]);
    console.log(...newarr);
    

//还原数组
arr = arr.concat(newarr)
console.log(arr);

}



// splice(参数一，参数二，参数三)
// 参数三：要替换的值
    console.log(arr.splice(0,1,'天选之人'));
    
    </script>
</body>
</html>